home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / util / blank / bserver_v14.lha / BServer_v1.4 / Sources.lha / Sources / clients / Clock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-23  |  3.9 KB  |  165 lines

  1. ;/*
  2. sc RESOPT DATA=NEAR UCHAR CONSTLIB STREQ NMINC STRMERGE NOSTKCHK NOSTDIO OPTIMIZE OPTSIZE IGNORE=73+94 Clock.c
  3. slink from LIB:c.o Clock.o to //Clients/Clock LIB LIB:sc.lib LIB:amiga.lib /lib/client.lib SC SD NOICONS STRIPDEBUG
  4. delete Clock.o
  5. quit
  6.  
  7.  Clock 1.2  (Client for BServer)
  8.  
  9.  Copyright © 1994-1995 by Stefano Reksten of 3AM - The Three Amigos!!!
  10.  All rights reserved.
  11. */
  12.  
  13. #include <exec/types.h>
  14. #include <exec/memory.h>
  15. #include <graphics/text.h>
  16. #include <graphics/rastport.h>
  17. #include <time.h>
  18.  
  19. #include <clib/alib_protos.h>
  20. #include <proto/exec.h>
  21. #include <proto/intuition.h>
  22. #include <proto/graphics.h>
  23. #include <proto/utility.h>
  24. #include <proto/diskfont.h>
  25. #include <proto/icon.h>
  26.  
  27. #include "/include/client.h"
  28.  
  29. char *ver = "$VER: Clock 1.2 "__AMIGADATE__;
  30.  
  31. struct IntuitionBase *IntuitionBase;
  32. struct GfxBase *GfxBase;
  33. struct Library *UtilityBase, *IconBase, *DiskfontBase;
  34. struct DisplayIDInformation *dinfo;
  35.  
  36. struct TextAttr tattr = { "topaz.font", 8, 0, FPF_DISKFONT };
  37. struct TextFont *newfont;
  38.  
  39. char clkstring[5] = { ' ','0',':','0','0' };
  40. struct IntuiText itext = { 1, 0, JAM1, 0, 0, NULL, clkstring, NULL };
  41.  
  42. extern ULONG RangeSeed;
  43.  
  44. void DrawClock( void )
  45. {
  46. struct Screen *scr;
  47. UWORD swidth, sheight, xcrd, ycrd;
  48. struct Rectangle *rect;
  49. ULONG secs, mics, ticks, drawn = 0;
  50. struct ClockData clock;
  51. UWORD fontheight;
  52. UBYTE brightness;
  53.  
  54. rect = GETTXTOSCANRECT(dinfo);
  55.  
  56. swidth = RECTANGLEWIDTH(rect);
  57. sheight = RECTANGLEHEIGHT(rect);
  58. brightness = GETBRIGHTNESS(dinfo);
  59.  
  60. if ( scr = OpenScreenTags( NULL,
  61.     SA_DisplayID, DISPLAYID( dinfo ),
  62.     SA_Width, swidth,
  63.     SA_Height, sheight,
  64.     SA_Left, (RECTANGLEWIDTH(rect) - swidth)/2,
  65.     SA_Top, 0,
  66.     SA_Depth, 1,
  67.     SA_Overscan, OSCAN_TEXT,
  68.     SA_Type, CUSTOMSCREEN,
  69.     SA_Quiet, TRUE,
  70.     TAG_END ) )
  71.     {
  72.     register struct ViewPort *vp = &(scr->ViewPort);
  73.     register struct RastPort *rp = &(scr->RastPort);
  74.  
  75.     SpritesOff();
  76.  
  77.     SetRGB4( vp, 0, 0, 0, 0 );
  78.     SetRGB4( vp, 1, 5*brightness/100, 10*brightness/100, 15*brightness/100 );
  79.  
  80.     fontheight = ( newfont ? newfont->tf_YSize : rp->Font->tf_YSize );
  81.  
  82.     ticks = 200;
  83.     while( STILL_BLANKING )
  84.         {
  85.         WaitTOF();
  86.  
  87.         if ( ticks++ == 200 )
  88.             {
  89.             ticks = 0;
  90.             if ( drawn++ )
  91.                 {
  92.                 itext.FrontPen = 0;
  93.                 PrintIText( rp, &itext, xcrd, ycrd );
  94.                 }
  95.             CurrentTime( &secs, &mics );
  96.             Amiga2Date( secs, &clock );
  97.             clkstring[0] = ( clock.hour >= 10 ? '0' + clock.hour / 10 : ' ' );
  98.             clkstring[1] = '0' + clock.hour % 10;
  99.             clkstring[3] = '0' + clock.min / 10;
  100.             clkstring[4] = '0' + clock.min % 10;
  101.             itext.FrontPen = 1;
  102.             xcrd = RangeRand( swidth - IntuiTextLength( &itext ));
  103.             ycrd = RangeRand( sheight - fontheight );
  104.             PrintIText( rp, &itext, xcrd, ycrd );
  105.             }
  106.         }
  107.  
  108.     CloseScreen( scr );
  109.     SpritesOn();
  110.     }
  111. else
  112.     SendClientMsg( ACTION_FAILED );
  113. }
  114.  
  115.  
  116. void __main( char *line )
  117. {
  118. if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 37L ) )
  119.     {
  120.     if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 37L ) )
  121.         {
  122.         if ( UtilityBase = OpenLibrary( "utility.library", 37L ) )
  123.             {
  124.             if ( IconBase = OpenLibrary( "icon.library", 37L ) )
  125.                 {
  126.                 struct DiskObject *obj;
  127.  
  128.                 if ( obj = GetDiskObject( "Clock" ) )
  129.                     {
  130.                     char **tooltypes = obj->do_ToolTypes;
  131.                     tattr.ta_YSize = ArgInt( tooltypes, "FONTHEIGHT", 8 );
  132.                     tattr.ta_Name = ArgString( tooltypes, "FONTNAME", "topaz.font" );
  133.  
  134.                     if ( DiskfontBase = OpenLibrary( "diskfont.library", 37L ) )
  135.                         {
  136.                         if ( newfont = OpenDiskFont( &tattr ) )
  137.                             {
  138.                             tattr.ta_Flags = newfont->tf_Flags;
  139.                             itext.ITextFont = &tattr;
  140.                             }
  141.  
  142.                         if ( dinfo = OpenCommunication() )
  143.                             {
  144.                             RangeSeed = time( NULL );
  145.                             DrawClock();
  146.                             CloseCommunication( dinfo );
  147.                             }
  148.  
  149.                         if ( newfont )
  150.                             CloseFont( newfont );
  151.  
  152.                         CloseLibrary( DiskfontBase );
  153.                         }
  154.                     FreeDiskObject( obj );
  155.                     }
  156.                 CloseLibrary( IconBase );
  157.                 }
  158.             CloseLibrary( UtilityBase );
  159.             }
  160.         CloseLibrary( (struct Library *)GfxBase );
  161.         }
  162.     CloseLibrary( (struct Library *)IntuitionBase );
  163.     }
  164. }
  165.